/**
*
* TaskName : AcceleratorLogon
* Purpose : accelerator logon
* Entry Points : anywhere
* Exit Points : store , language ,ffm select
* Inputs :
*		logonId
*		logonPassword
* Outputs :
*		logonName
* Tables : 
* Complete : Working
* Comments : 
*/

package com.ibm.commerce.url.tasks.accelerator;

import com.ibm.commerce.url.harness.*;
import com.ibm.commerce.url.util.Log;
import com.ibm.commerce.url.exception.*;
import com.ibm.wc.test.exception.DatablockMissingException;

import java.util.LinkedHashMap;
import java.util.Map;

public class AcceleratorLogon extends URLTestTask {

	public static final String INPUT_PARAMETER_NAME_LOGONID = "logonId";
	public static final String INPUT_PARAMETER_NAME_LOGONPASSWORD = "logonPassword";
	
	public static final String OUTPUT_PARAMETER_NAME_LOGONNAME="logonName";
	
	private static AcceleratorLogon instance = new AcceleratorLogon();
	private AcceleratorLogon(){}
	
	public static void execute() throws TaskFailException, DatablockMissingException {
		instance.runTask();
	}
	public static void execute(int counterIndex) throws TaskFailException, DatablockMissingException {
		instance.runTask(counterIndex);
	}

	protected void executeTask() throws TaskFailException {
		acceleratorLogonStep1();
		acceleratorLogonStep2();
		acceleratorLogonStep3();
	}

	private void acceleratorLogonStep1() throws TaskFailException {
		Log.finest("Task["+this.getClass().getSimpleName()+"]: Entering acceleratorLogonStep1");
		
		WebHit("https://standardhost/accelerator", WEB_FORM_GET);
		
		Log.finest("Task["+this.getClass().getSimpleName()+"]: Exiting acceleratorLogonStep1");
	}
	
	private static Map<String, String> acceleratorLogonStep2_FORM = new LinkedHashMap<String, String>();
	static{
		acceleratorLogonStep2_FORM.put("XMLFile","common.mcLogon");
	}
	private void acceleratorLogonStep2() throws TaskFailException{
		Log.finest("Task["+this.getClass().getSimpleName()+"]: Entering acceleratorLogonStep2");
		
		WebHit("https://standardhost/webapp/wcs/tools/servlet/ToolsLogon", WEB_FORM_POST, acceleratorLogonStep2_FORM);
		
		Log.finest("Task["+this.getClass().getSimpleName()+"]: Exiting acceleratorLogonStep2");	
	}
	
	private static Map<String, String> acceleratorLogonStep3_FORM = new LinkedHashMap<String, String>();
	static{
		acceleratorLogonStep3_FORM.put("BrowserOk","true");
		acceleratorLogonStep3_FORM.put("XMLFile","common.mcLogon");
		acceleratorLogonStep3_FORM.put("slurl","StoreLanguageSelection");
		acceleratorLogonStep3_FORM.put("mcurl","MerchantCenterView?XMLFile=common.merchantCenter");
		acceleratorLogonStep3_FORM.put("reLogonURL","ToolsLogon?XMLFile=common.mcLogon");		
		acceleratorLogonStep3_FORM.put("URL","StoreLanguageSelection");
		acceleratorLogonStep3_FORM.put("logonId","");
		acceleratorLogonStep3_FORM.put("logonPassword","");
	}
	private void acceleratorLogonStep3() throws TaskFailException{	
		Log.finest("Task["+this.getClass().getSimpleName()+"]: Entering acceleratorLogonStep3");
		
		
		putParameterInMap(acceleratorLogonStep3_FORM, "logonId", getParameterFromDataFile(INPUT_PARAMETER_NAME_LOGONID));
		putParameterInMap(acceleratorLogonStep3_FORM, "logonPassword", getParameterFromDataFile(INPUT_PARAMETER_NAME_LOGONPASSWORD));
		
		WebHit("https://standardhost/webapp/wcs/tools/servlet/Logon", WEB_FORM_POST, acceleratorLogonStep3_FORM);
			
		putParameterInOutputMap(OUTPUT_PARAMETER_NAME_LOGONNAME, acceleratorLogonStep3_FORM.get("logonId"));
		
		Log.finest("Task["+this.getClass().getSimpleName()+"]: Exiting acceleratorLogonStep3");
	}
	
}
